#!/usr/bin/env python
# -*- coding: utf8 -*-

from qtpy import QtWidgets, QtCore, QtGui
from .frameless_movable_widget import FramelessMovableWidget
from .ui.window_title_widget import Ui_window_title_widget



class WindowTitleWidget(FramelessMovableWidget):
    def __init__(self, parent):
        super(WindowTitleWidget, self).__init__(parent)
        self._ui = Ui_window_title_widget()
        self._ui.setupUi(self)
        self.setWindowFlags(QtCore.Qt.FramelessWindowHint | QtCore.Qt.WindowSystemMenuHint)
        self.setWindowOpacity(0)
        self.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)

        self.setStyleSheet('''background-color:rgb(25,25,25);''')
        self._ui.logo.setStyleSheet('font:87 10pt "Arial Black";color:rgb(200, 200, 200);')

        self._parent = parent
        # 无边框透明
        # self.setAttribute(Qt.WA_TranslucentBackground)
        self.maxNormal=False
        self._ui.close_btn.clicked.connect(self._on_close_btn_clicked)
        self._ui.min_btn.clicked.connect(self._on_min_btn_clicked)
        #self.max_btn.clicked.connect(self._on_max_btn_clicked)

    def set_icon(self, path):
        _icon = QtGui.QIcon()
        _icon.addPixmap(QtGui.QPixmap(path), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self._ui.icon_btn.setIcon(_icon)


    def set_window_title(self, text):
        self._ui.logo.setText(text)


    def _on_min_btn_clicked(self):
        self._parent.showMinimized()

    def _on_max_btn_clicked(self):
        if(self.maxNormal):
            self._parent.showNormal()
            self.maxNormal= False
        else:
            self._parent.showMaximized()
            self.maxNormal=  True

    def _on_close_btn_clicked(self):
        self._parent.close()

    def enterEvent(self, event):
        self._parent.set_default()
